// 语言包
var chi = require('../../utils/Chinese.js')
var eng = require("../../utils/English.js")
//获取应用实例
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        language: '',
        // 语言包对象
        content: '',
        // 新添加地址
        name: '',
        tel: '',
        coders: '',
        add: '',
        select: "circle",
        posi: { name: "", tel: "", add: "", default: '', coders: '',  }
    },
    // 输入框
    nameInput: function (e) {
        
        this.data.posi.name = e.detail.value
    },
    telInput: function (e) {
        this.data.posi.tel = e.detail.value
    },
    codersInput: function (e) {
        this.data.posi.coders = e.detail.value
    },
    addInput: function (e) {
        this.data.posi.add =  e.detail.value
    },
    change: function (e) {
        var that = this
        if(that.data.select == 'circle'){
           
            that.setData({
                select:'success'
            })
            that.data.posi.default = true
        }else{
            that.setData({
                select:'circle'
            })
            that.data.posi.default = false
        }
        
      },
    on: function () {
        let that = this
        that.setData({
            language: app.data.language,
        })
        var lastLanuage = that.data.language
        if (lastLanuage == 'zh_CN') {
            that.setData({
                content: chi.content,
            })
            wx.setNavigationBarTitle({
                title: '编辑地址'
            })
        } else if (lastLanuage == 'zh_EN') {
            that.setData({
                content: eng.content,
            })
            // 修改导航标题
            wx.setNavigationBarTitle({
                title: 'Edit Address'
            })
        }
    },
    formSubmit: function (e) {
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
        console.log(this.data.posi)
        app.data.posi = this.data.posi
        app.data.add_show = true
        wx.redirectTo({
          url: '../order_infor/order_infor',
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        that.on()
        that.setData({
          name: app.data.add_edit.name,
          tel: app.data.add_edit.tel,
          coders: app.data.add_edit.coders,
          add: app.data.add_edit.add,
         
        })
        if(app.data.add_edit.default == true){
          that.setData({
            select: 'success',
          })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})